//
//  EJSShopCartGoodsCell.m
//  EnjoyShoppingStreet
//
//  Created by lifayu on 2017/12/19.
//  Copyright © 2017年 lifayu. All rights reserved.
//

#import "EJSShopCartGoodsCell.h"
#import "EJSShoppingCartGoodsModel.h"

@implementation EJSShopCartGoodsCell{
    EJSShoppingCartGoodsModel *_goodsModel;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}
- (IBAction)selectAction:(UIButton *)sender {
    if([self.delegate respondsToSelector:@selector(shopCartGoodsCell:selectGoods:)]){
        [self.delegate shopCartGoodsCell:self selectGoods:_goodsModel];
    }
}
- (IBAction)addAction:(id)sender {
    if([self.delegate respondsToSelector:@selector(shopCartGoodsCell:addGoodsNum:)]){
        [self.delegate shopCartGoodsCell:self addGoodsNum:_goodsModel];
    }
}

- (IBAction)substractAction:(id)sender {
    if([self.delegate respondsToSelector:@selector(shopCartGoodsCell:substractGoodsNum:)]){
        [self.delegate shopCartGoodsCell:self substractGoodsNum:_goodsModel];
    }
}
- (IBAction)deleteAction:(id)sender {
    if([self.delegate respondsToSelector:@selector(shopCartGoodsCell:deleteGoods:)]){
        [self.delegate shopCartGoodsCell:self deleteGoods:_goodsModel];
    }
}

- (void)setShoppingGoodsCartModel:(EJSShoppingCartGoodsModel *)model{
    _goodsModel = model;
    [self.goodsImageView setImageWithUrl:model.cover];
    self.countLabel.text = [NSString stringWithFormat:@"%d", model.num.intValue / model.minToBuy.intValue];
    self.priceLabel.text = model.price;
    self.goodsNameLabel.text = model.spuName;
    self.origenPriceLabel.text = model.originPrice.stringByDeletingPathExtension;
    self.goodsSkuId.text = [NSString stringWithFormat:@"货号: %@", model.sn];
    self.minimumCountLabel.text = [NSString stringWithFormat:@"%@/%@", model.minToBuy, model.unit];
    /*删除线*/
    if (!FLYStringIsEmpty(model.originPrice)) {
        NSUInteger length = [model.originPrice length];
        NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:model.originPrice];
        [attri addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlinePatternSolid | NSUnderlineStyleSingle) range:NSMakeRange(0, length)];
        [attri addAttribute:NSStrikethroughColorAttributeName value:AppMainColor range:NSMakeRange(0, length)];
        [self.origenPriceLabel setAttributedText:attri];
    }

}

@end
